<template>
    <div>
      <h1>当前数字：</h1>
      <div>{{ currentNumber || '等待中...' }}</div>
    </div>
  </template>
  
  <script setup>
  import { ref, onMounted } from 'vue'
  
  const currentNumber = ref(null)
  
  onMounted(() => {
    // const eventSource = new EventSource('http://127.0.0.1:6010/source-event')
    const eventSource = new EventSource('http://127.0.0.1:6010/generate_stream')
  
    eventSource.onmessage = function (event) {
      currentNumber.value = event.data
    }
  
    eventSource.onerror = function (err) {
      console.error('EventSource 发生错误：', err)
      currentNumber.value = '连接异常'
    }
  })
  </script>
  
  <style scoped>
  h1 {
    color: #333;
  }
  
  div {
    font-size: 24px;
    margin-top: 10px;
  }
  </style>